#coding=utf-8

from db import *
from deal_analyse import DealAnalyzer

def get_r_by_threshold(con, code, exdate):
    
    da = DealAnalyzer(con, code, exdate)
    da.set_thresholds()
    r = da.get_results_by_threshold()

    return r

def addlist(pre,current):
    r = []
    for i in range(len(pre)):
        if i == 0 : r[i] = current[i] 
        else:
            r[i] = pre[i] + current[i]

    return r

def accumulate_bs(con, code, start_day):
    
    exdays = exday.get_exdays_after(con, code, start_day)
    
    bs_everyday = []
    for d in exdays:
        data = get_r_by_threshold(con, code, d)
        bs_everyday.append(data)
    
    acc = [bs_everyday[0], ]
    pre = bs_everyday[0]
    
    for r in bs_everyday[1:]:
    
        r = addlist(pre + r) 
        acc.append(r)       
        pre = r
        
    return acc
    
              
        
        
        
        
        
        
        
        
        
        


    

